<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>

<!--页面内容开始-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>用户会员等级
会员当前所处的等级列表 </h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <div class="m-l-xs toolbar">
                            <button class="btn btn-sm btn-primary" type="button"
                                    onclick="memberuserlevelListObj.addOrUpdateHandle()"><i
                                    class="fa fa-plus"></i>&nbsp;新增
                            </button>
                            <button id="memberuserlevelList_delAll" class="btn btn-sm btn-danger" type="button"
                                    disabled="disabled"
                                    onclick="memberuserlevelListObj.deleteHandle()"><i
                                    class="fa fa-trash"></i>&nbsp;批量删除
                            </button>
                        </div>
                        <table id="memberuserlevelList_table" class="table table-striped"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页面内容结束-->
<div th:replace="web/member/memberuserlevel-add-or-update::memberuserlevelAddOrUpdate"></div>
<script type="text/javascript">
    $().ready(function () {
         memberuserlevelListObj.initTable();
    })
    var memberuserlevelListObj = new Object({
        dataListSelections: [],
        myTable: $('#memberuserlevelList_table'),
        addOrUpdateHandle: function (id) {
            memberuserlevelAddOrUpdateObj.init(id);
        },
        deleteHandle: function (id) {
            let ids = id ? [id] :
                    this.dataListSelections.map(item => {
                        return item.id;
                    });
            let tipMsg = id ? '删除' : '批量删除';
            $.mySwalConfirm(`将${tipMsg}，确认吗？`, function () {
                $.myPost({
                    url: `/member/memberuserlevel/delete`,
                    dataType: "json",
                    data: ids,
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            memberuserlevelListObj.refreshDataList();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        },
        checkRowHander: function () {
            memberuserlevelListObj.dataListSelections = memberuserlevelListObj.myTable.bootstrapTable('getSelections');
            if (memberuserlevelListObj.dataListSelections.length > 0) {
                $('#memberuserlevelList_delAll').removeAttr("disabled");
            } else {
                $('#memberuserlevelList_delAll').attr("disabled", "disabled");
            }
        },
        refreshDataList: function () {
            memberuserlevelListObj.myTable.bootstrapTable('refresh');
        },
        initTable: function () {
            memberuserlevelListObj.myTable.bootstrapTable({
                toolbar: ".toolbar",
                search: true,
                trimOnSearch: true,
                pagination: true,
                sidePagination: 'server',
                url: '/member/memberuserlevel/list',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                queryParams: function (param) {
                    return param;
                },
                onCheck: function (row, $element) {
                    memberuserlevelListObj.checkRowHander();
                },
                onUncheck: function (row, $element) {
                    memberuserlevelListObj.checkRowHander();
                },
                onCheckAll: function (row, $element) {
                    memberuserlevelListObj.checkRowHander();
                },
                onUncheckAll: function (row, $element) {
                    memberuserlevelListObj.checkRowHander();
                },
                onCheckSome: function (row) {
                    memberuserlevelListObj.checkRowHander();
                },
                onUncheckSome: function (row) {
                    memberuserlevelListObj.checkRowHander();
                },
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    checkbox: true,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                                            {
                            title: 'ID',
                            field: 'id'
                        },
                                            {
                            title: '版本',
                            field: 'version'
                        },
                                            {
                            title: '排序',
                            field: 'sort'
                        },
                                            {
                            title: '创建人',
                            field: 'createUser'
                        },
                                            {
                            title: '创建时间',
                            field: 'createTime'
                        },
                                            {
                            title: '更新人',
                            field: 'updateUser'
                        },
                                            {
                            title: '更新时间',
                            field: 'updateTime'
                        },
                                            {
                            title: '备注',
                            field: 'remark'
                        },
                                            {
                            title: '删除标识',
                            field: 'deleted'
                        },
                                            {
                            title: '用户ID',
                            field: 'userId'
                        },
                                            {
                            title: '等级信息ID',
                            field: 'levelId'
                        },
                                        {
                        title: '操作',
                        align: 'center',
                        width: 100,
                        events: {
                            'click .edit': function (e, value, row, index) {
                                    memberuserlevelListObj.addOrUpdateHandle(row.id)
                            },
                            'click .trash': function (e, value, row, index) {
                                    memberuserlevelListObj.deleteHandle(row.id)
                            }
                        },
                        formatter: function (value, row, index) {
                            var opers = [];
                            opers.push(`<a class="edit btn btn-white btn-bitbucket text-success" title="编辑">
                                    <i class="fa fa-edit"></i>
                                </a>`)
                            opers.push(`<a class="trash btn btn-white btn-bitbucket text-info" title="删除">
                                    <i class="fa fa-trash"></i>
                                </a>`)
                            return opers.join('');
                        }
                    }],
                responseHandler: function (res) {
                    return {
                        total: res.page.totalCount,
                        rows: res.page.list
                    };
                }
            });
        }
    })
</script>
</body>
</html>